﻿using BCDto.Sim.CompanyBelongArea;
using BCService.Sim.CompanyBelongArea;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.Organization.CompanyBelongArea
{
    /// <summary>
    /// 公司归属区域管理
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class CompanyBelongAreaController : ManagementBaseController
    {
        private readonly ICompanyBelongAreaService companyIdBelongAreaService;

        public CompanyBelongAreaController(ICompanyBelongAreaService companyIdBelongAreaService)
        {
            this.companyIdBelongAreaService = companyIdBelongAreaService;
        }

        /// <summary>
        /// 设置公司归属区域
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <param name="dtos">归属区域列表</param>
        /// <response code="200">设置公司归属区域成功。</response>
        /// <returns></returns>
        [HttpPost("{company_id}")]
        [Log("设置公司归属区域")]
        [ProducesResponseType(typeof(IEnumerable<CompanyBelongAreaDto>), 200)]
        public IActionResult Post([FromRoute(Name = "company_id")] int companyId, [FromBody] List<CompanyBelongAreaRequestDto> dtos)
        {
            return Ok(this.companyIdBelongAreaService.SettingBelongArea(this.Admin, companyId, dtos));
        }

        /// <summary>
        /// 获取公司其他公司已设置的归属区域列表
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <response code="200">获取部门归属区域列表。</response>
        /// <returns></returns>
        [HttpGet("[action]/{company_id}")]
        [ProducesResponseType(typeof(IEnumerable<CompanyBelongAreaDto>), 200)]
        public IActionResult OtherBelongArea([FromRoute(Name = "company_id")] int companyId)
        {
            return Ok(this.companyIdBelongAreaService.OtherBelongArea(companyId));
        }

        /// <summary>
        /// 获取公司归属区域列表
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <response code="200">获取部门归属区域列表。</response>
        /// <returns></returns>
        [HttpGet("{company_id}")]
        [ProducesResponseType(typeof(IEnumerable<CompanyBelongAreaDto>), 200)]
        public IActionResult Get([FromRoute(Name = "company_id")] int companyId)
        {
            return Ok(this.companyIdBelongAreaService.Query(companyId));
        }
    }
}
